<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>title</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>

<body>
<div class="layuimini-container" id="app">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>游戏枚举常量配置</legend>
            <div style="margin:10px;">

                <button type="button" style=" margin-bottom: 20px;" class="layui-btn" id="ConstCfg" title="ConstCfg.csv">
                    <i class="layui-icon layui-icon-upload"></i> ConstCfg
                </button>
                <button type="button" style=" margin-bottom: 20px;"   class="layui-btn" id="SkillBase" title="SkillBase.csv">
                    <i class="layui-icon layui-icon-upload"></i> SkillBase
                </button>
                <button type="button"  style=" margin-bottom: 20px;"  class="layui-btn" id="AuxiliarySkill" title="AuxiliarySkill.csv">
                    <i class="layui-icon layui-icon-upload"></i> AuxiliarySkill
                </button>
                <button type="button" style=" margin-bottom: 20px;"  class="layui-btn" id="BufferBase" title="BufferBase.csv">
                    <i class="layui-icon layui-icon-upload"></i> BufferBase
                </button>
                <button type="button" style=" margin-bottom: 20px;"  class="layui-btn" id="MonsterBase" title="MonsterBase.csv">
                    <i class="layui-icon layui-icon-upload"></i> MonsterBase
                </button>
                <button type="button" style=" margin-bottom: 20px;"  class="layui-btn" id="CallMonster" title="CallMonster.csv">
                    <i class="layui-icon layui-icon-upload"></i> CallMonster
                </button>
                <button type="button"  style=" margin-bottom: 20px;"  class="layui-btn" id="Collection" title="Collection.csv">
                    <i class="layui-icon layui-icon-upload"></i> Collection
                </button>
                <button type="button" style=" margin-bottom: 20px;"  class="layui-btn" id="EquipBase" title="EquipBase.csv">
                    <i class="layui-icon layui-icon-upload"></i> EquipBase
                </button>
                <button type="button"  style=" margin-bottom: 20px;"  class="layui-btn" id="EquipSyntAttr" title="EquipSyntAttr.csv">
                    <i class="layui-icon layui-icon-upload"></i> EquipSyntAttr
                </button>
                <button type="button"style=" margin-bottom: 20px;"  class="layui-btn" id="EquipSynthesize" title="EquipSynthesize.csv">
                    <i class="layui-icon layui-icon-upload"></i> EquipSynthesize
                </button>
                <button type="button"style=" margin-bottom: 20px;"  class="layui-btn" id="EquipInteMate" title="EquipInteMate.csv">
                    <i class="layui-icon layui-icon-upload"></i> EquipInteMate
                </button>
                <button type="button" style=" margin-bottom: 20px;"  class="layui-btn" id="EquipInteAttr" title="EquipInteAttr.csv">
                    <i class="layui-icon layui-icon-upload"></i> EquipInteAttr
                </button>
                <button type="button" style=" margin-bottom: 20px;"  class="layui-btn" id="ItemBase" title="ItemBase.csv">
                    <i class="layui-icon layui-icon-upload"></i> ItemBase
                </button>
                <button type="button" style=" margin-bottom: 20px;"  class="layui-btn" id="TaskContent" title="TaskContent.csv">
                    <i class="layui-icon layui-icon-upload"></i> TaskContent
                </button>

                <button type="button" style=" margin-bottom: 20px;"  class="layui-btn" id="EventTaskWeight" title="EventTaskWeight.csv">
                    <i class="layui-icon layui-icon-upload"></i> EventTaskWeight
                </button>
                <button type="button" style=" margin-bottom: 20px;"  class="layui-btn" id="TaskBase" title="TaskBase.csv">
                    <i class="layui-icon layui-icon-upload"></i> TaskBase
                </button>
                <button type="button" style=" margin-bottom: 20px;"  class="layui-btn" id="ItemDrop" title="ItemDrop.csv">
                    <i class="layui-icon layui-icon-upload"></i> ItemDrop
                </button>
                <button type="button" style=" margin-bottom: 20px;"  class="layui-btn" id="DropData" title="DropData.csv">
                    <i class="layui-icon layui-icon-upload"></i> DropData
                </button>
                <button type="button" style=" margin-bottom: 20px;"  class="layui-btn" id="RewardBase" title="RewardBase.csv">
                    <i class="layui-icon layui-icon-upload"></i> RewardBase
                </button>
            </div>
        </fieldset>
        <form class="layui-form layui-form-pane" action="" lay-filter="table-search">
        <div class="layui-form-item">
            <label class=" layui-form-label">选择区服：</label>
            <div class="layui-input-block">
                <input type="checkbox" class="area_checkbox" lay-filter="area_checkbox"
                       name="game_area[]" v-for="(item,index) in services" :title="item.name" :data-index="index"
                       :value="item.server_id" :checked="item.checked" />
            </div>
        </div>
            <div class="layui-form-item">
                <label class=" layui-form-label">选择配置表：</label>
                <div class="layui-input-block">
                    <input type="checkbox" class="area_checkbox" lay-filter="area_checkbox"
                           name="game_excl[]" v-for="(item,index) in excllist" :title="item.name" :data-index="index"
                           :value="item.exclid" :checked="item.checked" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-inline clearfix">
                    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm left" lay-submit="" lay-filter="check" id="check">
                        校验
                    </button>
                    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm left" lay-submit="" lay-filter="push" id="push">
                        同步
                    </button>
                </div>
            </div>
        </form>
        </div>
            <table class="layui-table">
                <thead>
                    <tr>
                        <th>上传文件名</th>
                        <th>操作时间</th>
                        <th>上传用户</th> <!--版本匹配不一致后事件处理-->

                    </tr>
                </thead>
                <tbody>
                    <tr v-for="item in versionEventList">
                        <td>
                            {{item.filename}}
                        </td>
                        <td>
                            <p>{{item.created_at}}</p>
                        </td>
                        <td>
                            <p>{{item.username}}</p>
                        </td>


                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
<style>
    .all-message,.version{
        line-height: 30px;
    }
</style>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/common.js?v=5" charset="utf-8"></script>
<script>
    var _this = this;
    var serviceList = JSON.parse(localStorage.getItem('services'));
    var services = [];
    for(var k in serviceList){
        if(serviceList[k].can_push==1) {
            services.push(serviceList[k])
        }
    }
    var $;
    new Vue({
        el:"#app",
        data:{
            services:services,
            hostVersion :'',
            excllist: [
                { exclid: "LST_CONST", name: '常量表', checked: false },
                { exclid: "LST_SKILL", name: '技能基础配置表', checked: false },
                { exclid: "LST_AUXILIARYSKILL", name: '辅助技能配置', checked: false },
                { exclid: "LST_BUFF", name: 'buff', checked: false },
                { exclid: "LST_MONSTER", name: '怪物基础', checked: false },
                { exclid: "LST_CALLMONSTER", name: '召唤怪物怪', checked: false },
                { exclid: "LST_COLLECTION", name: '采集表 ', checked: false },
                { exclid: "LST_EQUIP_ALL", name: '所有装备配置表', checked: false },
                { exclid: "LST_ITEM", name: '道具基础配置表', checked: false },
                { exclid: "LST_TASK", name: '任务配置表', checked: false },
                { exclid: "LST_DROP", name: '掉落配置表 ', checked: false },
                { exclid: "LST_NUMBER", name: 'LST_NUMBER', checked: false },
            ],
            versionEventList:[],
        },
        created(){
            _this = this
        },
        methods:{
            getGameAreas:function(){
                var gameAreas = [];
                var array = $('#thisForm').serializeArray();
                for (var k in array){
                    var v = array[k]
                    if (v.name == "game_area[]"){
                        gameAreas.push(parseInt(v.value))
                    }
                }
                return gameAreas;
            }
        },
        mounted(){
            layui.use(['form'], function () {
               var form = layui.form,$ = layui.$,laytpl=layui.laytpl;
                $.get('/admin/uploadrecord/list',{},function (res) {
                    if (res.code===0){
                        _this.versionEventList = res.data.slice(0, 30);
                    }
                })


                form.on('submit(push)', function(data){
                    var formData = data.field;

                    var gameAreas = [];
                    for(var k in formData){
                        var v = formData[k]
                        if (k.indexOf('game_area[') !==-1 ){
                            gameAreas.push(v)
                        }
                    }
                    formData.gameAreas = gameAreas
                    var excllist = [];
                    for(var k in formData){
                        var v = formData[k]
                        if (k.indexOf('game_excl[') !==-1 ){
                            excllist.push(v)
                        }
                    }
                    formData.excllist = excllist
                    $('#push').attr('disabled',true);
                    layer.confirm('您确定同步了么?',{title:"提示"},function() {
                        $.post("/admin/excelPush/push", formData, function (res) {
                            $('#submit').removeAttr('disabled');
                            if (res.code === 0) {
                                layer.msg('操作成功', {icon: 1, time: 2000}, function () {
                                    parent.location.reload();
                                })
                            } else {
                                layer.msg(res.msg, {icon: 5}, function () {
                                    parent.location.reload();
                                })

                            }
                        })
                    });
                    return false;
                });

                form.on('submit(check)', function(data){
                    var formData = data.field;
                    var gameAreas = [];
                    for(var k in formData){
                        var v = formData[k]
                        if (k.indexOf('game_area[') !==-1 ){
                            gameAreas.push(v)
                        }
                    }
                    formData.gameAreas = gameAreas
                    var excllist = [];
                    for(var k in formData){
                        var v = formData[k]
                        if (k.indexOf('game_excl[') !==-1 ){
                            excllist.push(v)
                        }
                    }
                    formData.excllist = excllist

                    $('#check').attr('disabled',true);
                    $.post("/admin/excelPush/check",formData,function(res){
                        $('#submit').removeAttr('disabled');
                        if (res.code === 0){
                            layer.msg('操作成功',{icon:1,time:5000},function(){
                                parent.location.reload();
                            })
                        }else {
                            layer.msg(res.msg,{icon:5},function () {
                                parent.location.reload();
                            })


                        }
                    })
                    return false;
                });


            });

            layui.use(['upload'],function () {
                var upload = layui.upload,$=layui.$;
                var excelMime = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";


                var tableReload = function(){
                    $.get('/admin/uploadrecord/list',{},function (res) {
                        if (res.code===0){
                            _this.versionEventList = res.data;
                        }
                    })
                }
                upload.render({
                    elem: '#any',
                    data:{table:'any',name:'any'},
                    exts:"xlsx",
                    acceptMime:excelMime,
                    trigger: 'click', //绑定点击事件
                    url:"/admin/excel/import",
                    done:function(res){
                        if (res.code !==0 ){
                            layer.msg(res.msg,{icon:2})
                        } else {
                            console.log( JSON.stringify(res.data) )
                            tableReload();
                            layer.msg('导入成功',{icon:1})
                        }
                    }
                });

                upload.render({
                    elem: '#ConstCfg',
                    data:{table:'ConstCfg',name:"ConstCfg.csv"},
                    auto:true,
                    accept:'file',
                    exts: "csv",
                    acceptMime: "text/csv",
                    url:"/admin/excelPush/import",
                    done:function(res){
                        if (res.code !==0 ){
                            layer.msg(res.msg,{icon:2})
                        } else {
                            tableReload();
                            layer.msg('导入成功',{icon:1})
                        }
                    }
                });

                upload.render({
                    elem: '#SkillBase',
                    data:{table:'SkillBase',name:"SkillBase.csv"},
                    auto:true,
                    accept:'file',
                    exts: "csv",
                    acceptMime: "text/csv",
                    url:"/admin/excelPush/import",
                    done:function(res){
                        if (res.code !==0 ){
                            layer.msg(res.msg,{icon:2})
                        } else {
                            tableReload();
                            layer.msg('导入成功',{icon:1})
                        }
                    }
                });

                upload.render({
                    elem: '#AuxiliarySkill',
                    data:{table:'AuxiliarySkill',name:"AuxiliarySkill.csv"},
                    auto:true,
                    accept:'file',
                    exts: "csv",
                    acceptMime: "text/csv",
                    url:"/admin/excelPush/import",
                    done:function(res){
                        if (res.code !==0 ){
                            layer.msg(res.msg,{icon:2})
                        } else {
                            tableReload();
                            layer.msg('导入成功',{icon:1})
                        }
                    }
                });

                upload.render({
                    elem: '#BufferBase',
                    data:{table:'BufferBase',name:"BufferBase.csv"},
                    auto:true,
                    accept:'file',
                    exts: "csv",
                    acceptMime: "text/csv",
                    url:"/admin/excelPush/import",
                    done:function(res){
                        if (res.code !==0 ){
                            layer.msg(res.msg,{icon:2})
                        } else {
                            tableReload();
                            layer.msg('导入成功',{icon:1})
                        }
                    }
                });
                upload.render({
                    elem: '#MonsterBase',
                    data:{table:'MonsterBase',name:"MonsterBase.csv"},
                    auto:true,
                    accept:'file',
                    exts: "csv",
                    acceptMime: "text/csv",
                    url:"/admin/excelPush/import",
                    done:function(res){
                        if (res.code !==0 ){
                            layer.msg(res.msg,{icon:2})
                        } else {
                            tableReload();
                            layer.msg('导入成功',{icon:1})
                        }
                    }
                });

                upload.render({
                    elem: '#CallMonster',
                    data:{table:'CallMonster',name:"CallMonster.csv"},
                    auto:true,
                    accept:'file',
                    exts: "csv",
                    acceptMime: "text/csv",
                    url:"/admin/excelPush/import",
                    done:function(res){
                        if (res.code !==0 ){
                            layer.msg(res.msg,{icon:2})
                        } else {
                            tableReload();
                            layer.msg('导入成功',{icon:1})
                        }
                    }
                });

                upload.render({
                    elem: '#Collection',
                    data:{table:'Collection',name:"Collection.csv"},
                    auto:true,
                    accept:'file',
                    exts: "csv",
                    acceptMime: "text/csv",
                    url:"/admin/excelPush/import",
                    done:function(res){
                        if (res.code !==0 ){
                            layer.msg(res.msg,{icon:2})
                        } else {
                            tableReload();
                            layer.msg('导入成功',{icon:1})
                        }
                    }
                });

                upload.render({
                    elem: '#EquipBase',
                    data:{table:'EquipBase',name:"EquipBase.csv"},
                    auto:true,
                    accept:'file',
                    exts: "csv",
                    acceptMime: "text/csv",
                    url:"/admin/excelPush/import",
                    done:function(res){
                        if (res.code !==0 ){
                            layer.msg(res.msg,{icon:2})
                        } else {
                            tableReload();
                            layer.msg('导入成功',{icon:1})
                        }
                    }
                });

                upload.render({
                    elem: '#EquipSyntAttr',
                    data:{table:'EquipSyntAttr',name:"EquipSyntAttr.csv"},
                    auto:true,
                    accept:'file',
                    exts: "csv",
                    acceptMime: "text/csv",
                    url:"/admin/excelPush/import",
                    done:function(res){
                        if (res.code !==0 ){
                            layer.msg(res.msg,{icon:2})
                        } else {
                            tableReload();
                            layer.msg('导入成功',{icon:1})
                        }
                    }
                });

                upload.render({
                    elem: '#EquipSynthesize',
                    data:{table:'EquipSynthesize',name:"EquipSynthesize.csv"},
                    auto:true,
                    accept:'file',
                    exts: "csv",
                    acceptMime: "text/csv",
                    url:"/admin/excelPush/import",
                    done:function(res){
                        if (res.code !==0 ){
                            layer.msg(res.msg,{icon:2})
                        } else {
                            tableReload();
                            layer.msg('导入成功',{icon:1})
                        }
                    }
                });

                upload.render({
                    elem: '#EquipInteMate',
                    data:{table:'EquipInteMate',name:"EquipInteMate.csv"},
                    auto:true,
                    accept:'file',
                    exts: "csv",
                    acceptMime: "text/csv",
                    url:"/admin/excelPush/import",
                    done:function(res){
                        if (res.code !==0 ){
                            layer.msg(res.msg,{icon:2})
                        } else {
                            layer.msg('导入成功',{icon:1})
                        }
                    }
                });

                upload.render({
                    elem: '#EquipInteAttr',
                    data:{table:'EquipInteAttr',name:"EquipInteAttr.csv"},
                    auto:true,
                    accept:'file',
                    exts: "csv",
                    acceptMime: "text/csv",
                    url:"/admin/excelPush/import",
                    done:function(res){
                        if (res.code !==0 ){
                            layer.msg(res.msg,{icon:2})
                        } else {
                            tableReload();
                            layer.msg('导入成功',{icon:1})
                        }
                    }
                });


                upload.render({
                    elem: '#ItemBase',
                    data:{table:'ItemBase',name:"ItemBase.csv"},
                    auto:true,
                    accept:'file',
                    exts: "csv",
                    acceptMime: "text/csv",
                    url:"/admin/excelPush/import",
                    done:function(res){
                        if (res.code !==0 ){
                            layer.msg(res.msg,{icon:2})
                        } else {
                            tableReload();
                            layer.msg('导入成功',{icon:1})
                        }
                    }
                });


                upload.render({
                    elem: '#TaskContent',
                    data:{table:'TaskContent',name:"TaskContent.csv"},
                    auto:true,
                    accept:'file',
                    exts: "csv",
                    acceptMime: "text/csv",
                    url:"/admin/excelPush/import",
                    done:function(res){
                        if (res.code !==0 ){
                            layer.msg(res.msg,{icon:2})
                        } else {
                            tableReload();
                            layer.msg('导入成功',{icon:1})
                        }
                    }
                });

                upload.render({
                    elem: '#EventTaskWeight',
                    data:{table:'EventTaskWeight',name:"EventTaskWeight.csv"},
                    auto:true,
                    accept:'file',
                    exts: "csv",
                    acceptMime: "text/csv",
                    url:"/admin/excelPush/import",
                    done:function(res){
                        if (res.code !==0 ){
                            layer.msg(res.msg,{icon:2})
                        } else {
                            tableReload();
                            layer.msg('导入成功',{icon:1})
                        }
                    }
                });


                upload.render({
                    elem: '#TaskBase',
                    data:{table:'TaskBase',name:"TaskBase.csv"},
                    auto:true,
                    accept:'file',
                    exts: "csv",
                    acceptMime: "text/csv",
                    url:"/admin/excelPush/import",
                    done:function(res){
                        if (res.code !==0 ){
                            layer.msg(res.msg,{icon:2})
                        } else {
                            tableReload();
                            layer.msg('导入成功',{icon:1})
                        }
                    }
                });

                upload.render({
                    elem: '#ItemDrop',
                    data:{table:'ItemDrop',name:"ItemDrop.csv"},
                    auto:true,
                    accept:'file',
                    exts: "csv",
                    acceptMime: "text/csv",
                    url:"/admin/excelPush/import",
                    done:function(res){
                        if (res.code !==0 ){
                            layer.msg(res.msg,{icon:2})
                        } else {
                            tableReload();
                            layer.msg('导入成功',{icon:1})
                        }
                    }
                });

                upload.render({
                    elem: '#DropData',
                    data:{table:'DropData',name:"DropData.csv"},
                    auto:true,
                    accept:'file',
                    exts: "csv",
                    acceptMime: "text/csv",
                    url:"/admin/excelPush/import",
                    done:function(res){
                        if (res.code !==0 ){
                            layer.msg(res.msg,{icon:2})
                        } else {
                            tableReload();
                            layer.msg('导入成功',{icon:1})
                        }
                    }
                });


                upload.render({
                    elem: '#RewardBase',
                    data:{table:'RewardBase',name:"RewardBase.csv"},
                    auto:true,
                    accept:'file',
                    exts: "csv",
                    acceptMime: "text/csv",
                    url:"/admin/excelPush/import",
                    done:function(res){
                        if (res.code !==0 ){
                            layer.msg(res.msg,{icon:2})
                        } else {
                            tableReload();
                            layer.msg('导入成功',{icon:1})
                        }
                    }
                });


            })

        }
    })

</script>
</body>
</html>